Skip to content

London|May-2025|KhilolaRustamova|Module-Structuring-&-Testing-Data|sprint 3 #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

HilolaRustam
Copy link

@HilolaRustam HilolaRustam commented Jul 3, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@HilolaRustam HilolaRustam changed the title London|May-2025|KhilolaRCoursework/sprint 3 London|May-2025|KhilolaRustamova|Module-Structuring-&-Testing-Data|sprint 3 Jul 3, 2025
@HilolaRustam HilolaRustam added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Participant to add when requesting review labels Jul 3, 2025
@illicitonion illicitonion added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Jul 15, 2025
@illicitonion illicitonion changed the base branch from to-be-deleted-coursework/sprint-3 to main July 15, 2025 12:14
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally looking good, I left a few things for you to think about.


if (num >= 2 && num <= 9) return num;

throw new Error("Invalid card rank");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this exception is thrown, it may not be clear to the caller what the invalid rank was - can you think how to make this more clear?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have any thoughts here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new Error(Invalid card rank: "${rank}"from card "${card}" ); would be more clear to specify what card was wrong.

Comment on lines +14 to +16
if (["K", "Q", "J", "10"].includes(rank)) return 10;

const num = parseInt(rank);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but: either of these lines of code could handle the value 10 - why did you decide to handle it in the K/Q/J case rather than the number case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By grouping "10" with "K", "Q", and "J", you make the intention clear:

"These are all cards that are worth 10 points, no matter what."

It also avoids need of extra range check (num === 10) in the number parsing block, which could make the logic more complex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your thoughts on the grouping, but in terms of the code, I think a different grouping may make sense here.

"These are all cards whose value is exactly what's written" vs "These are cards we need to treat specially" feels like a more important difference to me than "These are cards worth 10 points".

And in terms of logic complexity, you already have an upper bound in your range check. So I think:

if (["K", "Q", "J"].includes(rank)) return 10;

// ...

if (num >= 2 && num <= 10) return num;

is actually simpler than

if (["K", "Q", "J", "10"].includes(rank)) return 10;

// ...

if (num >= 2 && num <= 9) return num;

Including "10" in the array involves writing more code. Either way you need an upper bound on the num case, so the difference is really just whether you have an extra element in the array.

@@ -22,3 +22,6 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

console.log(countChar("hello", "l")); // Should print 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are correct expectations, but they're not tests written in Jest - can you try to write actual tests for these cases?

@@ -13,20 +13,36 @@ test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hellohellohello");
expect(repeat(str, count)).toEqual("hellohellohello");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this line? What was broken about what it did before?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(repeat(str, count)).toEqual("hellohellohello");
Calls the repeat() function directly inside the test.
It’s like saying: “Call the function now with str and count, and I expect it to return "hellohellohello".”

before it was saying "I expect the value stored in repeatedStr to equal "hellohellohello"

It might not be broken but i find it unnecessary step

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is makes sense but you probably want to delete the repeatedStr variable if you're going to do this.
Right now is slightly the worst of both situations - you have the extra variable but you're not using it which is confusing. I agree that calling repeat directly in the assertion is fine and clear!

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 15, 2025
@HilolaRustam HilolaRustam added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jul 17, 2025
@illicitonion illicitonion added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review 📅 Sprint 3 Assigned during Sprint 3 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants